<?php
function echoo($txt){
    echo $txt.'<br>';
}
function addisnum($IssueNum,$StartTime){
	//echoo('期号：'.$IssueNum .'开始时间：' .$StartTime.' '.date('Y-m-d H:i:s',$StartTime));
  if(!$IssueNum || !$StartTime) return;
  $list=M('lotteryrecord')->where(array('IssueNum'=>$IssueNum))->count();
  if(!$list){
	//echoo($IssueNum.'需要插入数据 开始时间：'.$StartTime.' '.date('Y-m-d H:i:s',$StartTime));
    $data2['IssueNum']=$IssueNum;
    $data2['StartTime']=$StartTime;
    $data2['EndTime']=$StartTime+60;
    $ss=M('lotteryrecord')->data($data2)->add();
  }
  return $ss;
}
function addallsj($mm){
    if($mm<5){
      M('sj')->where(array('Id' => 1))->data(array('hongtl' => 0,'DFW' => 0))->save();
    }else{
      $data2 = array(
      'hongtl' => array('exp', '`hongtl`+'.(mt_rand(6000,400000)*100)),
      'DFW' => array('exp', '`DFW`+'.(mt_rand(6000,400000)*100)),
      );
      M('sj')->where(array('Id' => 1))->data($data2)->save();
      //echo M('sj')->getlastsql();
    }
}

   function getOrderId(){
      return date("YmdHis")."".rand(1000000,9999999);
   }
    function CreatNum($num){
        for ($i=1;$i<1000;$i++) {
            $aar=mt_rand($i,999);
            $bar=(substr($aar,-1,1)+substr($aar,-2,1)+substr($aar,-3,1));
            //echo $aar.'<br>';
            if($num==1){
                if($bar%2==0) return $aar;
            }else if($num==2){
                if($bar%2>0) return $aar;
            }else{
                return $aar;
            }
        }
    }
    function GetIssueNum(){//获取当前下注期号
          list($s1,$s2)=explode(' ',microtime());
          $s3= (float)sprintf('%.0f',(floatval($s1)+floatval($s2))*1000);
          $StartTime=strtotime(date('Y-m-d H:i',$s2));
          $S4=($StartTime+30)*1000;
          $nTime=$S4-$s3;
          $IssueNum=(date('Ymd',$s2)*10000)+(ceil(($s2-strtotime(date('Y-m-d',$s2)))/60));
          if ($nTime<0) {//这一分钟已经过了
            $StartTime=strtotime(date('Y-m-d H:i',$s2+60));
            $S4=$S4+60000;
            $nTime=$S4-$s3;
            $IssueNum=$IssueNum+1;
          }
          $EndTime=$StartTime+60;
          $list['IssueNum']=$IssueNum;
          //$data['LotteryNum']=;
          $list['StartTime']=$StartTime;
          $list['EndTime']=$EndTime;
          //$data['LotteryTime']=;
          //$list['Status']=0;
          //$list['CreateTime']='';
          //$list['EditTime']='';
          //$list['KJhm']='';
          $data['success']=true;
          //$data['msg']='';
          $data['list']=$list;
          $data['nTime']=$nTime;
          //$this->ajaxReturn($data);
          return $data;
    }
    function CheckCode() {
		$config = array(
        'useImgBg'  =>  false,           // 使用背景图片 
        'useCurve'  =>  false,            // 是否画混淆曲线
        'useNoise'  =>  false,            // 是否添加杂点  
        'fontSize'  =>  18,              // 验证码字体大小(px)
        'imageH'    =>  30,               // 验证码图片高度
        'imageW'    =>  105,               // 验证码图片宽度
        'length'    =>  4,               // 验证码位数
		);
		ob_clean();
	    $Verify = new \Think\Verify($config);
		$Verify->codeSet = '23456789ABCDEFGHJKLMNPQRTUVWXY';
		$Verify->fontttf   = '1.ttf';
		$Verify->entry();
    }
	function check_verify($code) {
        $verify = new \Think\Verify ();
	    return $verify->check ( $code );
    }